<?php
/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2018/3/24
 * Time: 22:50
 */

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

class Cards extends Model
{
    public $timestamps=true;
    protected $table='cards';
    
    public function series()
    {
        return $this->belongsTo(CardSeries::class);
    }
    
    public function scopeValid($query)
    {
        return $query->where('startTime','<',Carbon::now()->toDateTimeString())
            ->where('endTime','>',Carbon::now()->toDateTimeString())
            ->where('probability','>',0);
    }
    
    public function getImgAttribute()
    {
        if(!$this->attributes['img'])return '';
        return starts_with($this->attributes['img'],'http') ? $this->attributes['img'] : config('filesystems.disks.admin.url').$this->attributes['img'];
    }

}